import apiClient from '../apiClient';

import {
  GetListReq,
  GetListRes,
  UpdateListReq,
  UpdateLisRes,
  ListStatusReq,
  ListStatusRes,
} from '@/common/types';

export enum DocApi {
  GetList = '/openapi/v2/dataset/type/list',
  CreateType = '/openapi/v2/dataset/type/create',
  DelteType = '/openapi/v2/dataset/type/delete',
  UpdateList = '/openapi/v2/dataset/type/update',
  UploadFile = '/openapi/v2/dataset/type/import',
  ListStatus = '/openapi/v2/dataset/datasetset/status',
}

const getList = (params: GetListReq) => apiClient.get<GetListRes>({ url: DocApi.GetList, params });

const createList = (data: { dataset_tag_list: string[] }) =>
  apiClient.post<{ existing_types: string[] }>({ url: DocApi.CreateType, data });

const deleteList = (data: { dataset_tag_list: string[] }) =>
  apiClient.delete<null>({ url: DocApi.DelteType, data });

const updateList = (data: UpdateListReq) =>
  apiClient.put<UpdateLisRes>({ url: DocApi.UpdateList, data });

const uploadFile = (data: FormData) =>
  apiClient.post<{ existing_types: string[] }>({
    url: DocApi.UploadFile,
    data,
    headers: { 'Content-Type': 'multipart/form-data' },
  });

const listStatus = (data: ListStatusReq) =>
  apiClient.post<ListStatusRes>({ url: DocApi.ListStatus, data });

export default {
  getList,
  createList,
  deleteList,
  updateList,
  uploadFile,
  listStatus,
};
